package lgkj.meicqt20.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

import lgkj.meicqt20.R;
import lgkj.meicqt20.bean.HairstyleEntity;
import lgkj.meicqt20.utils.CommUtils;

/**
 * Created by Administrator on 2017/8/21 0021.
 */

public class HairstyleAdapter extends BaseAdapter {
    private Context context;
    private List<HairstyleEntity.DataBean> data;

    public HairstyleAdapter(Context context) {
        this.context = context;
        data = new ArrayList<>();
    }

    private int mpositon = 0;

    public void setpositon(int positon) {
        this.mpositon = positon;
    }


    public void setData(List<HairstyleEntity.DataBean> mdata) {
        this.data = mdata;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public HairstyleEntity.DataBean getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder = null;
        if (view == null) {
            holder = new Holder();
            view = LayoutInflater.from(context).inflate(R.layout.item_hairstyle, null);
            holder.fl_select = view.findViewById(R.id.fl_select);
            holder.iv_img = view.findViewById(R.id.iv_img);
            view.setTag(holder);

        } else {
            holder = (Holder) view.getTag();
        }
        CommUtils.LoadImage(context, holder.iv_img, data.get(i).getHairstyle_img(), R.drawable.common_icon_err);
        if (mpositon != i) {
            holder.fl_select.setBackgroundResource(0);
        } else {
            holder.fl_select.setBackgroundResource(R.drawable.zxsxzbk);
        }
        return view;
    }

    class Holder {
        FrameLayout fl_select;
        ImageView iv_img;
    }


}
